<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xh<!-tml1-transitional.dtd">
<%@page import="bridge.*"%>
<%@page import="java.net.URLEncoder"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modify Sensors</title>
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
</head>
<body>
<div id="header">
	<div id="logo">
		<h1>Bridge Viz</h1>
	</div>
	<!-- end #logo -->
	<div id="menu">
		<ul>
			<li><a href="project.jsp">The Project</a></li>
			<li><a href="sensors.jsp">Sensor Info</a></li>
			<li><a href="visualization.jsp">Data Visualization</a></li>
			<li><a href="records.jsp">Records</a></li>
			<li><a href="about.jsp">About Us</a></li>
			<li class="active"><a href="#">Administration</a></li>
		</ul>
	</div>
	<!-- end #menu -->
</div>
<!-- end #header -->
<div id="page">
	<div id="content">
		<div class="post">
			<h2 class="title">Sensor List</h2>
			<div class="entry">
				<%
					String old_id = request.getParameter("oldid");
					String new_id = request.getParameter("newid");
					String name = request.getParameter("name");
					String type = request.getParameter("type");
					String description = request.getParameter("description");
					DatabaseAccessor db = null;
					Sensor[] sensors = null;
					String[] types = null;
					db = DatabaseAccessor.getInstance();
					if(old_id != null && new_id != null && name != null && type != null && description != null)
					{
						out.println("<p>Updated sensor " + new_id + "</p>");
						out.println("<!--" + db.modifySensor(old_id, new_id, name, type, description).replace("\n", "<br>") + "-->");
						
					}
					
					sensors = db.getSensors();
					types = db.getTypes();
				%>
				<table>
				<%for(int k = 0; k < sensors.length; k++) { %>
					<tr><td>Sensor ID</td><td>Sensor Name</td><td>Sensor Type</td></tr>
					<form action="modifysensors.jsp" method="get"><input type='hidden' name='oldid' value=<%=sensors[k].sensorID%>><tr><%="<td><input maxlength='3' size='3' type='text' name='newid' value='" + sensors[k].sensorID + "'></td><td><input maxlength='32' size='32' type='text' name='name' value='" + (sensors[k].name).replace("\"", "&#34;").replace("'", "&#39;") + "'></td><td>"%><select name="type"><%for(int j = 0; j <types.length; j++){out.print("<option value = '" + types[j] + "'"); if(sensors[k].type.type.equals(types[j])){out.print(" SELECTED");}out.println(">" + types[j] + "</option>");}%></select><%="</td>"%><td align='right'><input type="submit" value ="Modify"></td></tr>
					<tr><td colspan=4>Description</td></tr>
					<tr><td colspan=4><textarea name='description' cols=50 rows=3><%=db.getSensorDescription(sensors[k].sensorID)%></textarea></td></tr>
					</form>
				<%}%>
				</table>
			</div>
		</div>
	</div>
	<!-- end #content -->
	<div id="sidebar">
		<div id="sidebar-content">
			<ul>
				<li>
					<h2>Sensors</h2>
					<ul>
						<li><a href="modifysensors.jsp">View/Modify Sensors</a></li>
						<li><a href="addsensors.jsp">Add Sensor</a></li>
					</ul>
				</li>
				<li>
					<h2>Sensor Types</h2>
					<ul>
						<li><a href="modifysensortypes.jsp">View/Modify Sensor Types</a></li>
						<li><a href="addsensortypes.jsp">Add Sensor Type</a></li>
					</ul>
				</li>
				<li>
					<h2>Database</h2>
					<ul>
						<li><a href="builddb.jsp">Build Database</a></li>
					</ul>
				</li>
			</ul>
		</div>
	</div>
<!-- end #page -->
<div id="footer">
	<p>&copy; 2008. All Rights Reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
<!-- end #footer -->
</body>
</html>
